package com.smart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.common.PageInfo;
import com.smart.model.convert.ProjectItemConvert;
import com.smart.model.domain.ProjectItemDO;
import com.smart.model.dtomapper.ProjectWeeklyItemDtoMapper;
import com.smart.model.domain.ProjectWeeklyItemDO;
import com.smart.mapper.ProjectWeeklyItemMapper;
import com.smart.model.request.ProjectWeeklyItemPageRequest;
import com.smart.model.request.ProjectWeeklyItemRequest;
import com.smart.model.util.ProjectWeeklyItemConvert;
import com.smart.model.vo.ProjectItemVO;
import com.smart.service.ProjectWeeklyItemService;
import com.smart.model.vo.ProjectWeeklyItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class ProjectWeeklyItemServiceImpl extends ServiceImpl<ProjectWeeklyItemMapper, ProjectWeeklyItemDO> implements ProjectWeeklyItemService {
    @Autowired
    private ProjectWeeklyItemMapper projectWeeklyItemMapper;

    @Override
    public ProjectWeeklyItemVO getByKey(long id) {
        ProjectWeeklyItemDO projectWeeklyItemDO = getById(id);
        ProjectWeeklyItemVO projectWeeklyItemVO = ProjectWeeklyItemDtoMapper.INSTANCE.do2VO(projectWeeklyItemDO);
        return projectWeeklyItemVO;
    }

    @Override
    public PageInfo<ProjectWeeklyItemVO> pageQuery(ProjectWeeklyItemRequest request) {
        long count = projectWeeklyItemMapper.pageCount(request);
        List<ProjectWeeklyItemDO> list = projectWeeklyItemMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        List<ProjectWeeklyItemVO> projectWeeklyItemVOList = ProjectWeeklyItemConvert.buildProjectWeeklyItemVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), projectWeeklyItemVOList, count);
    }

    @Override
    public List<ProjectWeeklyItemVO> listQuery(ProjectWeeklyItemRequest request) {
        List<ProjectWeeklyItemDO> list = list();
        List<ProjectWeeklyItemVO> projectWeeklyItemVOS = ProjectWeeklyItemConvert.buildProjectWeeklyItemVoList(list);
        return projectWeeklyItemVOS;
    }

    @Override
    public Boolean add(ProjectWeeklyItemRequest request) {
        ProjectWeeklyItemDO projectWeeklyItemDO = ProjectWeeklyItemDtoMapper.INSTANCE.request2DO(request);
        save(projectWeeklyItemDO);
        return true;
    }

    @Override
    public Boolean updateByKey(ProjectWeeklyItemRequest request) {
        ProjectWeeklyItemDO projectWeeklyItemDO = ProjectWeeklyItemDtoMapper.INSTANCE.request2DO(request);
        save(projectWeeklyItemDO);
        return true;
    }

    @Override
    public Boolean deleteByKey(long id) {
        projectWeeklyItemMapper.deleteDOById(id);
        return true;
    }

    @Override
    public PageInfo<ProjectWeeklyItemVO> pageItemQuery(ProjectWeeklyItemPageRequest request) {
        long count = projectWeeklyItemMapper.pageItemCount(request);
        List<ProjectWeeklyItemDO> list = projectWeeklyItemMapper.pageItemQuery(request, request.getPageSize(), request.fetchOffSet());
        List<ProjectWeeklyItemVO> projectItemVOList = ProjectWeeklyItemConvert.buildProjectWeeklyItemVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), projectItemVOList, count);
    }
}
